package com.future.lock.common;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.future.baselib.entity.MessageEvent;
import com.future.baselib.utils.EventBusUtil;
import com.future.lock.R;
import com.future.lock.home.activity.LockNotesActivity;
import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTTransmitMessage;

/**
 * 个推接受推送服务
 * Created by Administrator on 2017/12/22 0022.
 */

public class GetuiIntentService extends GTIntentService {
    @Override
    public void onReceiveServicePid(Context context, int i) {
    }

    @Override
    public void onReceiveClientId(Context context, String s) {
    }

    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
//        if (Constants.isWaiting) {
//            Constants.isWaiting = false;
//            EventBusUtil.sendEvent(new MessageEvent(Constants.LOCK_OPEN));
//        }else {
        PendingIntent contentIntent =
                PendingIntent.getActivity(this, 0, new Intent(this, LockNotesActivity.class), 0);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .setSmallIcon(R.mipmap.ic_logo)
                .setContentTitle("开锁推送")
                .setContentText(new String(gtTransmitMessage.getPayload()))
                .setContentIntent(contentIntent);
        notificationManager.notify(1, builder.build());
        EventBusUtil.sendEvent(new MessageEvent(Constants.RED_POINT));
//        }
    }

    @Override
    public void onReceiveOnlineState(Context context, boolean b) {
    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {
    }
}
